// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ReviewAction.java

package com.boci.clientapp.trading.action;

import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.MainPanel;
import com.boci.clientapp.trading.*;
import com.boci.clientapp.trading.handler.TradingHandler;
import com.boci.clientapp.trading.vo.TradingVO;
import com.boci.common.action.AbstractAction;
import com.boci.common.constant.RequestTypeConst;
import com.boci.common.util.AppException;
import com.boci.common.util.StringUtil;
import java.util.HashMap;
import java.util.logging.Logger;

public class ReviewAction extends AbstractAction
{

    public ReviewAction()
    {
        strModName = "TRADING_MODULE";
        strTradingScr = "TRADING_SCREEN";
        strReviewScr = "REVIEW_TRADING_SCREEN";
        strConfirmScr = "CONFIRM_TRADING_SCREEN";
    }

    private void addExtraValues(HashMap pInpMap, boolean pHKMktFlag)
    {
        pInpMap.put("acctid", appServ.getAccountNo());
        pInpMap.put("userid", appServ.getUserID());
        if(!pHKMktFlag)
        {
            pInpMap.put("fraction", "no");
            if(pInpMap.get("ordtype").equals("MKT"))
                pInpMap.put("priceField", "Invalid");
            else
                pInpMap.put("priceField", "Valid");
        }
    }

    public void doProcess(HashMap pInpMap, String pActionType)
    {
    	try{
	        appServ.setBusy(true);
	        TradingScrPanel trdPanel = (TradingScrPanel)appServ.getMainPanel().getPanel(strModName, strTradingScr);
	        if(pActionType.equals("BACK"))
	            doBack(pInpMap, trdPanel);
	        else
	        if(pActionType.equals("CANCEL"))
	            doCancel(trdPanel);
	        else
	        if(pActionType.equals("SEND ORDER"))
	            doSendOrder(pInpMap, trdPanel);
	        TrdReviewScrPanel reviewPanel = (TrdReviewScrPanel)appServ.getMainPanel().getPanel(strModName, strReviewScr);
	        reviewPanel.resetDuplicateFlag();
    	}        
    	catch(AppException appEx)
        {
            logger.info(StringUtil.formatException(appEx));
            if(appEx.getErrorCode().equals("TRD00998") || appEx.getErrorCode().equals("TRD00999"))
            {
                TrdReviewScrPanel reviewPanel = (TrdReviewScrPanel)appServ.getMainPanel().getPanel(strModName, strReviewScr);
                reviewPanel.acceptDuplicate();
                appServ.showWarningDialog(null, appEx.getMessage());
            } else
            {
                appServ.showErrorDialog(null, appEx.getMessage());
            }
        }
        catch(Exception sysEx)
        {
            logger.severe(StringUtil.formatException(sysEx));
            appServ.showSysErrDialog();
        }
        finally
        {
            appServ.setBusy(false);
        }
        return;
    }

    private void doSendOrder(HashMap pInpMap, TradingScrPanel pTradingScrPanel)
        throws Exception
    {
        addExtraValues(pInpMap, pTradingScrPanel.getHKMktFlag());
        if(pTradingScrPanel.getHKMktFlag())
        {
            String strReqType = RequestTypeConst.BOCI_HK_TRADE_SEND_URL;
            TradingHandler tradingHandler = new TradingHandler(strReqType);
            TrdConfirmScrPanel confirmPanel = (TrdConfirmScrPanel)appServ.getMainPanel().getPanel(strModName, strConfirmScr);
            confirmPanel.refresh(tradingHandler.sendHKTrade(pInpMap));
            appServ.getMainPanel().showScreen(strModName, strConfirmScr);
        } else
        {
            String strReqType = RequestTypeConst.BOCI_US_TRADE_SEND_URL;
            TradingHandler tradingHandler = new TradingHandler(strReqType);
            TrdConfirmScrPanel confirmPanel = (TrdConfirmScrPanel)appServ.getMainPanel().getPanel(strModName, strConfirmScr);
            confirmPanel.refresh(tradingHandler.sendUSTrade(pInpMap));
            appServ.getMainPanel().showScreen(strModName, strConfirmScr);
        }
    }

    private void doCancel(TradingScrPanel pTradingScrPanel)
        throws Exception
    {
        pTradingScrPanel.refresh();
        appServ.getMainPanel().showScreen(strModName, strTradingScr);
    }

    private void doBack(HashMap pInpMap, TradingScrPanel pTradingScrPanel)
        throws Exception
    {
        TradingVO vo = new TradingVO("", "");
        vo.setSymbol((String)pInpMap.get("symbol"));
        vo.setPrice((String)pInpMap.get("price"));
        vo.setQuantity((String)pInpMap.get("qty"));
        if(pTradingScrPanel.getHKMktFlag())
            vo.setOrderType((String)pInpMap.get("orderType"));
        else
            vo.setOrderType((String)pInpMap.get("ordtype"));
        TradingTabSclPane tradingSclPane = (TradingTabSclPane)appServ.getMainPanel().getTab(strModName);
        tradingSclPane.backToTradingScreen();
        pTradingScrPanel.refresh(vo);
    }

    String strModName;
    String strTradingScr;
    String strReviewScr;
    String strConfirmScr;
}
